#include "Keyboard.h"

namespace core
{

bool Keyboard::_keys[ LAST ] = { };

Vector<IKeyboardListener*> Keyboard::_listeners;

void Keyboard::OnPressKey( KeyboardKey key )
{
	_keys[key] = true;

	for( IteratorPtr<IKeyboardListener*> listeners( _listeners.GetIterator( ) );
			!listeners->IsEnd( );
			listeners->Next( ) )
	{
		listeners->Current( )->KeyPressed( key );
	}
}

void Keyboard::OnReleaseKey( KeyboardKey key )
{
	_keys[key] = false;

	for( IteratorPtr<IKeyboardListener*> listeners( _listeners.GetIterator( ) );
			!listeners->IsEnd( );
			listeners->Next( ) )
	{
		listeners->Current( )->KeyReleased( key );
	}
}

bool Keyboard::IsKeyPressed( KeyboardKey key )
{
	return _keys[key];
}

void Keyboard::AddListener( IKeyboardListener* listener )
{
	_listeners.Add( listener );
}

void Keyboard::RemoveListener( IKeyboardListener* listener )
{
	_listeners.Remove( listener );
}
}
